/**
 * Project Name:jh
 * File Name:RadarTCPRXThread.java
 * Package Name:com.jh.listener
 * Date:下午5:24:01
 * Copyright (c) 2021, LZ All Rights Reserved.
 *
*/

package com.jh.comm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jh.utils.BlockingQueueUtils;
import com.jh.utils.SocketUtils;

/**
 * Description: <br/>
 * Date: 下午5:24:01 <br/>
 * 
 * @author lz E-mail:withitren@outlook.com
 * @version
 * @see
 */
public class RadarTCPRXThread extends Thread {
    static final Logger logger = LoggerFactory.getLogger(RadarTCPRXThread.class);

    String line = null;

    Socket s = null;

    BufferedReader br = null;

    //

    BlockingQueueUtils queueUtils = BlockingQueueUtils.getInstance();

    ArrayBlockingQueue<String> rxBq = queueUtils.getrxBq();

    @Override
    public void run() {
        logger.debug("--->" + "enter RadarTCPRXThread run!");
        try {
            s = SocketUtils.getSocket();
            br = new BufferedReader(new InputStreamReader(s.getInputStream(), "GB2312"));
        } catch (IOException e1) {

            logger.error(e1.getMessage(), e1);
        }
        while (true) {
            try {
                while ((line = br.readLine()) != null) {
                    logger.debug("--->" + "line :" + line);

                    System.out.println(
                            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "   readLine:   " + line);

                    rxBq.put(line);
                }
            } catch (IOException e) {

                logger.error(e.getMessage(), e);

            } catch (InterruptedException e) {

                logger.error(e.getMessage(), e);

            }
        }

    }
}
